<?php
/**
 * Controller_Index
 *
 * Класс Controller_Index отвечает за обработку главной страницы
 *
 * @author Дмитрий Кузьма <kouzma.d@gmail.com>
 * @version 1.0
 */
class Controller_Index extends Controller_Base {

	/**
	 * Выбор действия по URL
	 *
	 */
	public function action() {
	  Service_Debug::setDebug();
		$this->getIndex();
	}

	public function getIndex() {
		Service_Debug::setDebug();
		$objArticle = new Article();
		// Массив последних 5 статей
		$arrArticles = $objArticle->find('all', array('select' => '`article`.`ID_article`,`article`.`viewings`,`article`.`created_at`,`article`.`article_name`, `article`.`text`, `article`.`url` AS `article_url`, `category`.`url` AS `category_url`, `category`.`category_name`', 'joins' => 'LEFT JOIN `category` ON `article`.`ID_category` = `category`.`ID_category`', 'order' => '`article`.`created_at` DESC', 'limit' => 5));
		$objOrder = new Order();
		// Массив последних 5 заказов
		$arrOrders = $objOrder->find('all', array('select' => 'count(`order_response`.`ID_order_response`) as `order_responses`, `order`.`ID_order`, `order`.`order_name`,`order`.`description`,`order`.`created_at`,`city_url`.`city_name`', 'joins' => 'INNER JOIN  `city_url` USING(`city`) LEFT JOIN `order_response` USING (`ID_order`)', 'group' => 'ID_order', 'order' => 'created_at DESC','limit' => 5));
	  	$this->title = 'Главная страница';
	  	$this->bodyAttrs = 'class="main-page"';
	  	$objViewBlock = new View_Block();
	  
	  	$this->showHeader();
	  	$objViewBlock->showFastOrderBlock();
		$objViewBlock->showLastArticlesBlock($arrArticles);
		$objViewBlock->showLastOrdersBlock($arrOrders);
	  	$this->showFooter();

	}

}
?>